<template>
	<view class="wxloginbox">
		<fixtopVue>
			<template #l>
				<view class="fix-l" @click="back">
					关闭
				</view>
			</template>
		</fixtopVue>
		<view class="wxlogincon">
			<view class="tit-sq">
				<image src="../../static/logo-tm.png" mode="aspectFill"></image>
				<view class="wm">外卖(商家端)</view>
				<view class="sq">申请使用</view>
			</view>
			<view class="tit-t">
				你的微信头像 、昵称 、地区和性别信息
			</view>
			<view class="tip">登录即代表同意</view>
			<view class="userinfo">
				<view class="l">
					<image :src="useuserstore.wxuserinfo.avatarUrl" mode="aspectFill"></image>
				</view>
				<view class="r">
					<view class="rt">{{useuserstore.wxuserinfo.nickName}}</view>
					<view class="rb">微信个人信息</view>
				</view>
			</view>
			<view class="bu">
				  <view class="agree" @click="s_agree">同意</view>
				  <view class="" @click="back">拒绝</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import userstore from '@/store/userinfo.js'
	import {wxlogin} from '@/api/index.js'
	import fixtopVue from '../../components/fixtop/fixtop.vue';
	const useuserstore = userstore()
	const back = () => {
		uni.navigateBack()
	}
	const s_agree=()=>{
		uni.login({
			provider:"weixin",
			success(e) {
				const data={
					code:e.code,
					...useuserstore.wxuserinfo
				}
				loginwx(data)
			}
		})
	}
	//账号当前状态 0没开店  1申请中  2已开店 3账号冻结
	const loginwx=async(data)=>{
		const rudata=await wxlogin(data)
		if(rudata.code==200){
			useuserstore.userinfo=rudata.data
			uni.setStorageSync("token",rudata.token)
			if(rudata.data.kai==0){
				uni.showToast({
					title:"请申请开店！",
					icon:"none"
				})
				setTimeout(()=>{
				uni.reLaunch({
					url:"/pages/application/application"
				})
				},1500)
				return
			}else if(rudata.data.kai==1){
					 uni.reLaunch({
						url:"/pages/Audit/Audit"
					})
				return
			}else if(rudata.data.kai==3){
				console.log(33)
					uni.showToast({
						title:"账号已冻结！",
						icon:"none"
					})
					setTimeout(()=>{
					uni.reLaunch({
						url:"/pages/index/index"
					})
					},1500)
				return
			}
			uni.showToast({
				title:"登录成功！",
				icon:"none"
			})
			setTimeout(()=>{
			uni.reLaunch({
				url:"/pages/sy/sy"
			})
			},1500)
		}
	}
</script>

<style lang="scss" scoped>
	.wxloginbox {
		width: 100vw;
		height: 100vh;
		padding: 0 35rpx;
	}

	.fix-l {
		height: 100%;
		font-size: 25rpx;
		display: flex;
		align-items: center;
	}

	.wxlogincon {
		width: 100%;

		.tit-sq {
			margin-top: 30rpx;
			height: 100rpx;
			width: 100%;
			display: flex;
			align-items: center;
			gap: 20rpx;
			font-size: 25rpx;

			.sq {
				font-weight: 700;

			}

			.wm {
				margin-left: -45rpx;
			}

			image {
				height: 50rpx;
				width: 180rpx;
				// border: 1rpx solid rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				margin-left: -25rpx;
			}
		}

		.tit-t {
			width: 100%;
			height: 150rpx;
			font-size: 40rpx;
			font-weight: 700;
			line-height: 70rpx;
		}

		.tip {
			font-size: 25rpx;
			color: #7b7b7b;
			margin: 60rpx 0;
		}

		.userinfo {
			height: 90rpx;
			width: 100%;
			display: flex;
			align-items: center;
			gap: 20rpx;
            margin-top: 20rpx;
			.l {
				height: 90rpx;
				width: 90rpx;
				border-radius: 5rpx;
				overflow: hidden;

				image {
					height: 100%;
					width: 100%;
				}
			}

			.r {
				display: flex;
				flex-direction: column;
				gap: 10rpx;
				justify-content: center;

				.rt {
					font-size: 27rpx;
					font-weight: 700;
				}

				.rb {
					font-size: 23rpx;
					color: #7b7b7b;
				}
			}
		}
	       .bu{
			   width: 100%;
			   margin-top: 400rpx;
			   display: flex;
			   flex-direction: column;
			   justify-content: center;
			   align-items: center;
			   gap: 30rpx;
			   view{
				   width: 45%;
				   height: 70rpx;
				   background-color: #ededed;
				   border-radius: 10rpx;
				   display: flex;
				   align-items: center;
				   justify-content: center;
				   font-size: 25rpx;
				   font-weight: 700;
				   color: #07c160;
			   }
			   .agree{
				   background-color: #07c160;
				   color:#ededed ;
			   }
		   }
	}
</style>